<!--登录页面-->
<template>
  <div id="bigBox">
    <div id="login">
      <h2>用户登录</h2>
      <el-form :model="userLogin" ref="Login" :rules="rules">
        <el-form-item label="账号：" prop="userName">
          <el-input
            placeholder="请输入账号"
            v-model="userLogin.userName"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password" label="密码：">
          <el-input
            placeholder="请输入密码"
            show-password
            v-model="userLogin.password"
          ></el-input>
        </el-form-item>
        <div class="remember">
          <div>
            <el-checkbox v-model="checked">记住用户名</el-checkbox>
          </div>
          <div>
            <a>忘记密码</a>
          </div>
        </div>
        <el-form-item>
          <el-button type="primary" @click="onSubmit" class="login-btn"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import md5 from 'md5'
import { getUserInfo } from '@/api/index.js'
import { Message } from 'element-ui';
import req from '@/api/index.js'
import {req_login} from '@/api/login/index.js'
export default {
  watch: {
    checked: {
      immediate: true,
      handler(val) {
        console.log("val", val);
      },
    },
  },
  data() {
    return {
      checked: "true",
      userLogin: {
        userName: "",
        password: "",
      },
      rules: {
        userName: [
          {
            required: true,
            message: "不能为空",
            trigger: "blur",
          },
        ],
        password: [
          {
            required: true,
            message: "不能为空",
            trigger: "blur",
          },
        ],
      },
    };
  },

  components: {},

  computed: {},

  methods: {
    onSubmit() {
      this.$refs.Login.validate((valid) => {
        if (valid) {
          //md5加密
          console.log(md5(this.userLogin.password))
          let password = md5(md5(this.userLogin.password).split('').reverse().join(''))
          let data = {
            userName: this.userLogin.userName,
            token: password
          }
          req('login', data).then(res=>{
            if(res.data.code == '200'){
              console.log('req_login')
              localStorage.setItem('token','kdkasgkdfhdhadhsfs')
              this.$router.push({path:'/'})
            }
          })
        } else {
          Message({
              showClose: true,
              message: '失败!',
              type: 'error'
            });
        }
      });
    },
  },
};
</script>
<style lang="less" scoped>
#bigBox {
  // background-image: linear-gradient(120deg, #a1c4fd 0%, #c2e9fb 100%);
  // background-image: linear-gradient(
  //   -225deg,
  //   #77ffd2 0%,
  //   #6297db 48%,
  //   #1eecff 100%
  // );
  // background-image: linear-gradient(to top, #d0e0f3 0%, #e7f0fd 100%);
  display: flex;
  width: 100%;
  height: 100%;
  position: absolute;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  .login-btn {
    margin-top: 30px;
    width: 250px;
  }
}
.remember {
  display: flex;
  justify-content: space-between;
}
#login {
  background: rgb(234, 234, 234, 0.5);
  width: 350px;
  height: 400px;
  padding: 40px 50px;
  border-radius: 5px;
}
</style>